#subset on urban municipalities
brazil_data_models <- 
  brazil_data[brazil_data$urb == 1,] %>% 
  mutate(prop_doctors = prop_doctos) %>%
  mutate(elec_comp_index = elec_index)

doc_mod_brazil <- lm(prop_doctors ~ log10(pop)*elec_comp_index + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + align, data = brazil_data_models)
teacher_mod_brazil <- lm(teachers_prop ~ log10(pop)*elec_comp_index + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + align, data = brazil_data_models)
comm_mod_brazil <- lm(prop_comm_health ~ log10(pop)*elec_comp_index + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + align, data = brazil_data_models)
schools_mod_brazil <- lm(schools_prop ~ log10(pop)*elec_comp_index + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + align, data = brazil_data_models)
elec_mod_brazil <- lm(electr_share_2010 ~ log10(pop)*elec_comp_index + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + align, data = brazil_data_models)
water_mod_brazil <- lm(piped_water_share_2010 ~ log10(pop)*elec_comp_index + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + align, data = brazil_data_models)

mods_brazil <- list("Doctors" = doc_mod_brazil, 
                    "Teachers" = teacher_mod_brazil, 
                    "Health Centers" = comm_mod_brazil, 
                    "Schools" = schools_mod_brazil, 
                    "Electricity" = elec_mod_brazil, 
                    "Water" = water_mod_brazil)

options(scipen = 999)
modelsummary(mods_brazil,
             output = "./_4_outputs/table_oa_i.html",
             coef_omit = "Intercept|pop_growth|density|div_index|avg_income|salary|ill_rate|align",
             fmt = "%.1f",
             gof_map = c("nobs", "r.squared"),
             coef_rename = c("log10(pop)" = "Population (logged)",
                             "elec_comp_index" = "Partisan Fractionalization",
                             "log10(pop):elec_comp_index" = "Population X Fractionalization"),
             stars = T)
